package com.diandian.backend.eleme.retail.exchange.controller;

import com.diandian.backend.eleme.retail.exchange.req.GetSkuStockReq;
import com.diandian.backend.eleme.retail.exchange.req.SkuStockUpdateOneReq;
import com.diandian.backend.eleme.retail.exchange.service.BusinessSkuManageService;
import com.diandian.backend.eleme.retail.exchange.service.BusinessSkuStockManageService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.base.boot.starter.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 业务 - 饿了吗 - 商品 - 商品库存管理
 */
@RestController
@RequestMapping("/business/sku/stock/manage")
public class BusinessSkuStockManageController {

    private static final Logger logger = LoggerFactory.getLogger(BusinessSkuStockManageController.class);

    @Autowired
    private BusinessSkuStockManageService skuStockManageService;

    @Autowired
    private BusinessSkuManageService businessSkuManageService;

    /**
     * 单个修改商品库存
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/skuStockUpdateOne")
    public BaseResult skuStockUpdateOne(@RequestHeader(value = "source") String source,
                                        @RequestHeader(value = "secret") String secret,
                                        @RequestBody SkuStockUpdateOneReq data) throws Exception {
        return ResultUtil.makeResult(0, "success", skuStockManageService.skuStockUpdateOne(source, secret, data));
    }

    /**
     * 查询商品库存数据（基于：商品列表）
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/get")
    public BaseResult getSkuStock(@RequestHeader(value = "source") String source,
                              @RequestHeader(value = "secret") String secret,
                              @RequestBody GetSkuStockReq data){
        return ResultUtil.makeResult(businessSkuManageService.getSkuStock(source, secret, data));
    }
}
